import request from '@/utils/request';
import { formatParams } from '@/utils/index';

export function createArchive() {
    return request({
        url: '/audioArchive',
        method: 'POST',
    });
}

export function getArchiveList({ page = 1, size = 5, state, self = true } = {}) {
    return request({
        url: '/audioArchive',
        method: 'GET',
        params: { page, size, state, self },
    });
}

export function getArchive({ id }) {
    return request({
        url: `/audioArchive/${id}`,
        method: 'GET',
    });
}

export function setArchive({ id, title, cover, desc, state }) {
    return request({
        url: `/audioArchive/${id}`,
        method: 'PUT',
        data: { title, desc, cover, state },
    });
}

export function audioExamineList({ page = 1, size = 20 } = {}) {
    return request({
        url: '/audioArchiveExamine',
        method: 'GET',
        params: { page, size },
    });
}
export function audioArchiveExamine({ id, title, desc, state, comment }) {
    return request({
        url: `/audioArchiveExamine/${id}`,
        method: 'PUT',
        data: { title, desc, state, comment },
    });
}

export function delArchive({ id }) {
    return request({
        url: `/audioArchive/${id}`,
        method: 'DELETE',
    });
}
/**
 *
 * @param {number} archive_id 合辑id
 * @param {number} sort 排序id
 * @param {{}} resourceInfo 资源信息
 */
// export function createAudioResource(archive_id, sort, resourceInfo) {
//   return request({
//     url: '/audioResource',
//     method: 'POST',
//     data: { archive_id, sort, resourceInfo },
//   });
// }

export function editAudioResource(id, resourceInfo) {
    const columns = ['name', 'artist', 'desc', 'cover', 'lyric'];
    const updateData = formatParams(resourceInfo, columns);
    return request({
        url: `/audioResource/${id}`,
        method: 'PUT',
        data: { resourceInfo: updateData },
    });
}
/**
 * 排序资源接口
 * @param {[{id:number,sort:number}]} sortData 排序规则
 */
export function sortAudioResource(sortData) {
    return request({
        url: '/sortAudioResource',
        method: 'PUT',
        data: { sortData },
    });
}

export function deleteAudioResource({ id }) {
    return request({
        url: `/audioResource/${id}`,
        method: 'DELETE',
    });
}

export function getHistoryEditArchive() {
    return request({
        url: '/audioArchiveHistory',
        method: 'GET',
    });
}
// // 音频接口 - 分类 - 以分类搜索音频
// export function audioSearchByClssify(classify_id) {
//   return request({
//     url: `/audioSearchByClssify/${classify_id}`,
//     method: 'GET',
//   });
// }
// 音频接口 - 分类 - 列出所有音频分类
export function audioClassifyList() {
    return request({
        url: '/audioClassify',
        method: 'GET',
    });
}
// 音频接口 - 分类 - 删除音频分类
export function deleteAudioClassify(id) {
    return request({
        url: `/audioClassify/${id}`,
        method: 'DELETE',
    });
}
// 音频接口 - 分类 - 修改音频分类名称
export function updateAudioClassify(id, name) {
    return request({
        url: `/audioClassify/${id}`,
        method: 'PUT',
        data: { name },
    });
}
// 音频接口 - 分类 - 添加音频分类
export function createAudioClassify(name) {
    return request({
        url: '/audioClassify',
        method: 'POST',
        data: { name },
    });
}
// // 音频接口 - 分类 - 给音频设置分类
// export function archiveToClassify({ archive_id, classify_id }) {
//   return request({
//     url: '/archiveToClassify',
//     method: 'PUT',
//     data: { archive_id, classify_id },
//   });
// }
// 音频接口-审核 - 获取音频审核日志
export function audioExamineLog(page, size) {
    return request({
        url: '/audioExamineLog',
        method: 'GET',
        params: { page, size },
    });
}
